package net.bac.sbe.web.sonar.server;

import java.util.ArrayList;
import java.util.List;

import net.bac.sbe.web.sonar.client.ReportService;
import net.bac.sbe.web.sonar.client.view.ReportView;
import net.bac.sbe.web.sonar.server.dev.utils.xml.applications.ApplicationsConfig;
import net.bac.sbe.web.sonar.server.dev.utils.xml.applications.RepositoryType;
import net.bac.sbe.web.sonar.server.report.wrapper.ItemToRetainReportServiceWrapper;
import net.bac.sbe.web.sonar.server.report.wrapper.SonarInformationReportServiceWrapper;
import net.bac.sbe.web.sonar.server.service.locator.ServiceFactory;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class ReportServiceImpl extends RemoteServiceServlet implements
		ReportService {


	public ReportView generateSonarFilteredReport(String projectId,
			String projectAnalyst, String projectDescription, List<String> repositories, String repToCompare) {

		SonarInformationReportServiceWrapper wrapper = ServiceFactory.getServiceInstance(SonarInformationReportServiceWrapper.class);

		return wrapper.generateSonarFilteredReport(projectId,
				projectAnalyst, projectDescription, repositories, super.getServletContext(), repToCompare);
	}

	public ReportView generateItemToRetainReport(String projectName,
			String projectAnalyst, String projectDescription, List<String> repositories, String repToCompare) {

		ItemToRetainReportServiceWrapper wrapper = ServiceFactory.getServiceInstance(ItemToRetainReportServiceWrapper.class);

		return wrapper.generateItemToRetainReport(projectName,
				projectAnalyst, projectDescription, repositories, super.getServletContext(), repToCompare);
	}

	public List<ReportView> generateProjectReports(
			String projectId, String projectAnalyst, String projectDescription,
			List<String> repositories, List<String> reportsToGenerate, String repToCompare) {
		List<ReportView> result = new ArrayList<ReportView>(2);
		if(reportsToGenerate.contains("itemToRetainReport")){
			result.add(this.generateItemToRetainReport(projectId, projectAnalyst, projectDescription, repositories, repToCompare));
		}
		if(reportsToGenerate.contains("sonarReport")){
			result.add(this.generateSonarFilteredReport(projectId, projectAnalyst, projectDescription, repositories, repToCompare));
		}

		return result;
	}





}
